home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / aimHdrViewOverlay.js < prev    next >
Encoding:
JavaScript  |  2001-09-10  |  4.5 KB  |  147 lines

  1. /* This overlay JS file contains the JS necessary for integrating
  2.    AIM presence into the messenger msg header pane overlay (msgHdrViewOverlay).
  3.  
  4.    It allows us to dynamically modify the msg hdr view overlay to add 
  5.    presence indication for email addresses in that pane.
  6. */
  7.  
  8. /* we need to implement a data source observer on the buddy list so we
  9.    are notified when people are online or not 
  10. */ 
  11.  
  12.  
  13. // cache the properties we are interested in...
  14. var buddyStateString = RDF.GetResource("http://home.netscape.com/NC-rdf#BuddyStateString");
  15.  
  16. // This array of dom nodes is an array indexed by URI that keeps track of the
  17. // dom nodes in the msg header pane we care about...
  18. var domNodes = new Object();
  19.  
  20. var AimDataSourceObserver = 
  21. {
  22.   onAssert: function(datasource, source, property, target)
  23.   {
  24.     // onAssert is going to be called a lot, so make sure you try to kick out
  25.     // as early as possible to avoid any extra over head.....
  26.       if(source.EqualsNode(aimRDFSession()))
  27.       {
  28.           if(property.EqualsNode(aimRDFSessionState()))
  29.           {
  30.         var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  31.         // if we are going offline then be sure to clear the presence state for 
  32.         // all of the aim resources we are interested in.
  33.         if (state && state == "Offline")
  34.         {
  35.           for (i in domNodes)
  36.             domNodes[i].setAttribute("BuddyStateString", "Offline");
  37.         }
  38.       }
  39.     }
  40.     else if (property.EqualsNode(buddyStateString))
  41.     {
  42.       var targetString = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  43.       // dump("changing buddy state for" + source.Value + "with target: " + targetString + "\n");
  44.       var node = domNodes[source.Value];
  45.       //var node = domNodes[node];
  46.       if (node)
  47.         SetPresence(node, target);
  48.     }
  49.   },
  50.  
  51.   onUnassert: function(datasource, source, property, target)
  52.   {
  53.   },
  54.  
  55.   onChange: function(datasource, source, property, oldTarget, newTarget)
  56.   {
  57.     AimDataSourceObserver.onAssert(datasource, source, property, newTarget);
  58.   },
  59.  
  60.   onMove: function(datasource, oldSource, newSource, property, target)
  61.   {
  62.     AimDataSourceObserver.onAssert(datasource, newSource, property, target);
  63.   },
  64.  
  65.   beginUpdateBatch: function(datasource)
  66.   {
  67.   },
  68.  
  69.   endUpdateBatch: function(datasource)
  70.   {
  71.   }
  72. };
  73.  
  74. /* SetPresence updates the titled button image (node)
  75.    based on the property value of presence
  76. */
  77. function SetPresence(node, presence)
  78. {
  79.   if (node)
  80.   {
  81.    // if we have a node that corresponds to this URI, then we need to poke
  82.    // it....
  83.     var targetString = presence.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  84.     node.setAttribute("BuddyStateString", targetString);
  85.     // this silly align hack is because css isn't noticing the alignment
  86.     // attribute unless I set it to something...then set it back to what
  87.     // I really want...
  88.     node.setAttribute("align", "left");
  89.     node.setAttribute("align", "right");
  90.     node.setAttribute("max-height", "15px");
  91.   }
  92. }
  93.  
  94. /* Extract the AIM ID from the node and send an instant message
  95. */
  96. function SendIMFor (node)
  97. {
  98. //XXXjelwellXXX might need to change state from OnlineAway to Online
  99.   var target = aimRDFDataSource().GetTarget(aimRDFSession(), aimRDFSessionState(), true);
  100.   var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  101.   if ("OnlineAway" == state)
  102.   {
  103.     if ( aimLocateManager() ) {
  104.         aimLocateManager().SetUserInfoAwayMessage(null);
  105.     }
  106.   }
  107.  
  108.   if (node)
  109.   {
  110.     var screenName = node.getAttribute("IMScreenName");
  111.     if (screenName)
  112.     {
  113.       aimIMInvokeIMForm(screenName);
  114.     }
  115.     else
  116.       aimIMInvokeIMForm(null);
  117.   }
  118. }
  119.  
  120. function AddToBuddyListFor(node)
  121. {
  122. //XXXjelwellXXX might need to change state from OnlineAway to Online
  123.   if (node)
  124.   {
  125.     var screenName = node.getAttribute("IMScreenName");
  126.     openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", "modal=yes,titlebar,chrome", null, null, screenName);
  127.   }
  128. }
  129.  
  130. /* OnLoadAimHdrViewOverlay --> called when the overlay is first loaded...
  131.    This is where we will register ourself as an observer on the AIM data source.
  132. */
  133.  
  134. function OnLoadAimHdrViewOverlay ()
  135. {
  136.   aimRDFDataSource().AddObserver(AimDataSourceObserver);
  137. }
  138.  
  139. function OnUnLoadAimHdrViewOverlay ()
  140. {
  141.   aimRDFDataSource().RemoveObserver(AimDataSourceObserver);
  142. }
  143.  
  144. // Install our load handler
  145. addEventListener("load", OnLoadAimHdrViewOverlay, false);
  146. addEventListener("unload", OnUnLoadAimHdrViewOverlay, false);
  147.